// pages/address/address.js
let utils = require("../../utils/utils.js");
const app = getApp();
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		monthRecordUrl:'/myMonthCard/monthRecord',
		offset:0,
		limit:10,
		monthCardInfo:{useCount:0,residue:'',useDay:'',endTime:'',show:false}
		,nonOrder:false
        ,bottom:false
		,list_info:[],
		emptyLastImg:'/none-account.png',
		cardBglastImg:'/walletbg.png'
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {
	
	},
	
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		let that=this;
		let monthCardInfo=wx.getStorageSync('monthCardInfo');
		that.getRegionData();
		if(monthCardInfo.isJudge){
			let now = new Date();
			let monthEndTime = new Date(monthCardInfo.monthEndTime);  // 将指定日期转换为标准日期格式。Fri Dec 08 2017 20:05:30 GMT+0800 (中国标准时间)
			if(monthCardInfo.monthEndTime){
				this.data.monthCardInfo.useDay=utils.day(monthEndTime-now);
			};
			this.data.monthCardInfo.endTime=monthCardInfo.monthEndTime;
			this.data.monthCardInfo.show=true;
		}else{
			console.log(0)
			this.data.monthCardInfo.show=false;
		};
		this.setData({
			monthCardInfo:this.data.monthCardInfo
		})
		this.img();
	},
	img(){
		let emptyImg=app.globalData.baseimg+this.data.emptyLastImg;
		let cardBgImg=app.globalData.baseimg+this.data.cardBglastImg;
		this.setData({
			emptyImg,
			cardBgImg,
		});
	},
	getRegionData:function(){
		this.getListData();
	},
	getListData:function () {
		let that=this;
		let indexData=wx.getStorageSync('indexData');
		let monthCardInfo=wx.getStorageSync('monthCardInfo');
		let userData=indexData.user;
		let data = {
			'userId': userData.userId,
			'type': userData.type,
			'offset': that.data.offset,
			'limit': that.data.limit,
		};
		let _data={url:that.data.monthRecordUrl,data:data,methods:'post',nonelist:true};
		utils.request.call(_data,(res)=>{
			this.data.monthCardInfo.useCount=res.data.data.useCount;
			if(!monthCardInfo.usageCount||monthCardInfo.usageCount==''||monthCardInfo.usageCount==null){
				monthCardInfo.usageCount=0;
			};
			if(monthCardInfo.isNotLimited==0){
				this.data.monthCardInfo.residue='无限次';
			}else{
				this.data.monthCardInfo.residue=Number(monthCardInfo.usageCount)-Number(this.data.monthCardInfo.useCount);
			};
			this.setData({
				monthCardInfo:this.data.monthCardInfo
			});
			let orderLists=res.data.data.data.content;
			if (that.data.list_info.length == 0 || !that.data.list_info) {
				that.nonOrder = true;
			};
			if(orderLists.length>=0){
				const content = orderLists;
				if (content.length < that.data.limit) {
					// 最后一页不足10条的情况
					if(that.data.offset>0){
						that.data.bottom=true;
					};
					return false;
				};
				// 处理数据
				if (that.data.offset === 0) {
					that.data.list_info = content;
					//return false;
				} else {
					that.data.list_info = that.data.list_info.concat(content);
					return false;
				};
			};
		});
	},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {
		
	},
	
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {
	
	},
	
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {
	
	},
	
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
	
	},
	
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
	
	},
	
	
})
